<?php

namespace Modules\Admin\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Modules\Admin\Entities\ConfigGroup;
use Modules\Admin\Entities\Configuration;

class ConfigGroupSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        \Illuminate\Support\Facades\DB::table('sys_configuration')->truncate();
        \Illuminate\Support\Facades\DB::table('sys_config_group')->truncate();
        $datas = [
            [
                'name' => '站点配置',
                'sort' => 2,
                'configuration' => [
                    [
                        'label' => '标题',
                        'key' => 'site_title',
                        'val' => 'laravel6.0LTS后台管理',
                        'type' => 'input',
                        'content' => '',
                        'tips' => '',
                    ],
                    [
                        'label' => '关键词',
                        'key' => 'site_keywords',
                        'val' => '后台管理系统管理',
                        'type' => 'input',
                        'content' => '',
                        'tips' => '',
                    ],
                    [
                        'label' => '描述',
                        'key' => 'site_description',
                        'val' => '后台管理系统管理，laravel6，layuiadmin，layui',
                        'type' => 'textarea',
                        'content' => '',
                        'tips' => '',
                    ],

                ]
            ]
        ];
        foreach ($datas as $data) {
            $group = ConfigGroup::create([
                'name' => $data['name'],
                'sort' => $data['sort'],
            ]);
            if (isset($data['configuration']) && !empty($data['configuration'])) {
                foreach ($data['configuration'] as $configuration) {
                    $configuration['group_id'] = $group->id;
                    Configuration::create($configuration);
                }
            }
        }
    }

}
